//package com.zmn.plat.dubbo.impl.servcategory;
//
//import java.util.ArrayList;
//import java.util.Collections;
//import java.util.List;
//import java.util.Objects;
//import java.util.stream.Collectors;
//
//import javax.annotation.Resource;
//
//import org.apache.dubbo.config.annotation.Service;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.BeanUtils;
//import org.springframework.cache.annotation.Cacheable;
//import org.springframework.cglib.beans.BeanCopier;
//
//import com.zmn.common.constant.GlobalConsts;
//import com.zmn.common.dto.VtDTO;
//import com.zmn.common.dto2.ResponseDTO;
//import com.zmn.common.utils.collection.CollectionUtil;
//import com.zmn.common.utils.number.NumberUtil;
//import com.zmn.gateway.dubbo.client.GUserHolder;
//import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
//import com.zmn.plat.common.dictionary.PlatErrorCodeDict;
//import com.zmn.plat.common.dto.servcategory.ServCategoryDIO;
//import com.zmn.plat.common.dto.servcategory.ServCategoryDRO;
//import com.zmn.plat.dubbo.interfaces.servcategory.ServCategoryListRemoteService;
//import com.zmn.plat.dubbo.utils.DubboConsts;
//import com.zmn.plat.manager.interfaces.cache.ServCategoryCache;
//import com.zmn.plat.model.entity.servcategory.ServCategory;
//import com.zmn.plat.model.entity.servcategory.ServCategoryQuery;
//import com.zmn.plat.services.interfaces.servcategory.ServCategoryService;
//import com.zmn.plat.utils.bean.BeanCopyUtils;
//
//import lombok.extern.slf4j.Slf4j;
//
///**
// * @author duanzuocai
// * @version v1.0
// * @since 2018/10/19 10:42
// */
//@SuppressWarnings("Duplicates")
//@Service(version = DubboConsts.INTERFACE_VERSION, validation = "true")
//@Slf4j
//public class ServCategoryListRemoteServiceImpl implements ServCategoryListRemoteService {
//    private Logger logger = LoggerFactory.getLogger(ServCategoryListRemoteServiceImpl.class);
//
//    private static final String TAG = "产品分类 dubbo 接口";
//
//    @Resource
//    ServCategoryService servCategoryService;
//    @Resource
//    ServCategoryCache servCategoryCache;
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<ServCategoryDRO> getByCategoryId(Integer categoryId) {
//        logger.info(String.format("getByCategoryId参数:[%s]", "categoryId"));
//
//        if (NumberUtil.isNullOrZero(categoryId)) {
//            logger.error(String.format("[%s]参数:[%s]不能为空", TAG, "categoryId"));
//            return ResponseDTO.fromErrorCodeTable(PlatErrorCodeDict.ERROR_CODE_PANAM_NULL);
//        }
//
//        ServCategory category = servCategoryService.findByKey(categoryId);
//
//        if (Objects.isNull(category)) {
//            logger.error(String.format("[%s]参数:[%s]对应的Area对象不存在,errorCode:{}", TAG, "categoryId", PlatErrorCodeDict.ERROR_CODE_SERCATEGORY_CATEGORY_NULL));
//            return ResponseDTO.fromErrorCodeTable(PlatErrorCodeDict.ERROR_CODE_SERCATEGORY_CATEGORY_NULL);
//        }
//
//        ServCategoryDRO categoryDRO = new ServCategoryDRO();
//        BeanCopyUtils.copyProperties(category, categoryDRO);
//        return ResponseDTO.success(categoryDRO, GlobalConsts.SUCCESS_MSG);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ServCategoryDRO>> listAll() {
//        List<ServCategory> list = servCategoryCache.listAll();
//        List<ServCategoryDRO> items = list.stream().map(servCategory -> {
//            ServCategoryDRO servCategoryDRO = new ServCategoryDRO();
//            BeanUtils.copyProperties(servCategory, servCategoryDRO);
//            return servCategoryDRO;
//        }).collect(Collectors.toList());
//
//        return ResponseDTO.success(items, GlobalConsts.SUCCESS_MSG);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public com.zmn.common.dto2.ResponseDTO<List<VtDTO>> listServCategoryVt() {
//        return listServCategoryVtByLimitPermit(false);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public com.zmn.common.dto2.ResponseDTO<List<VtDTO>> listServCategoryVtByLimitPermit(Boolean limitPermit) {
//        Integer staffId = null;
//        if (limitPermit) {
//            staffId = GUserHolder.getCurrentLoginStaffId();
//            if (NumberUtil.isNullOrZero(staffId)) {
//                staffId = -1;
//            }
//        }
//        return listServCategoryVtByStaffId(staffId);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:serv:category:staff:' + #p0", cacheNames = "redis5m")
//    public com.zmn.common.dto2.ResponseDTO<List<VtDTO>> listServCategoryVtByStaffId(Integer staffId) {
//        log.info("listServCategoryVtByStaffId param is :{}", staffId);
//        // -1表示要求数据权限但未通过身份校验
//        if (NumberUtil.isNotNullOrZero(staffId) && staffId == -1) {
//            log.error("staffId is not aviable.errorCode:{}", PlatErrorCodeDict.ERROR_CODE_SERCATEGORY_IDENTITY_ERROR);
//            return ResponseDTO.fromErrorCodeTable(PlatErrorCodeDict.ERROR_CODE_SERCATEGORY_IDENTITY_ERROR);
//        }
//
//        // 取得全部分类列表
//        List<ServCategory> categories = servCategoryCache.listAll();
//        if (CollectionUtil.isNullOrEmpty(categories)) {
//            return com.zmn.common.dto2.ResponseDTO.success(Collections.EMPTY_LIST);
//        }
//
//        List<VtDTO> items = new ArrayList<>();
//        categories.forEach(category -> {
//            items.add(new VtDTO(category.getCategId(), category.getName(), category.getStatus()));
//        });
//
//        return com.zmn.common.dto2.ResponseDTO.success(items);
//
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ServCategoryDRO>> listByDIO(ServCategoryDIO query) {
//        if (Objects.isNull(query)) {
//            logger.error(String.format("[%s]参数:[%s]不能为空", TAG, "query"));
//            return ResponseDTO.fromErrorCodeTable(PlatErrorCodeDict.ERROR_CODE_PANAM_NULL);
//        }
//
//        ServCategory category = new ServCategory();
//        BeanCopyUtils.copyProperties(query, category);
//
//        List<ServCategory> list = servCategoryService.listByQuery(category);
//        BeanCopier copier = BeanCopier.create(ServCategory.class, ServCategoryDRO.class, false);
//        List<ServCategoryDRO> items = list.stream().map(servCategory -> {
//            ServCategoryDRO servCategoryDRO = new ServCategoryDRO();
//            copier.copy(servCategory, servCategoryDRO, null);
//            return servCategoryDRO;
//        }).collect(Collectors.toList());
//
//        return ResponseDTO.success(items, GlobalConsts.SUCCESS_MSG);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<Integer> countByQuery(ServCategoryDIO query) {
//        if (Objects.isNull(query)) {
//            logger.error(String.format("[%s]参数:[%s]不能为空", TAG, "query"));
//            return ResponseDTO.fromErrorCodeTable(PlatErrorCodeDict.ERROR_CODE_PANAM_NULL);
//        }
//
//        ServCategoryQuery servCategory = new ServCategoryQuery();
//        servCategory.setName(query.getName());
//        servCategory.setStatus(query.getStatus());
//        BeanCopyUtils.copyProperties(query, servCategory);
//        int count = servCategoryService.countByQuery(servCategory);
//        return ResponseDTO.success(count, GlobalConsts.SUCCESS_MSG);
//    }
//}
